package com.example.ranking.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.example.petinfo.dto.PetInfoRespDTO;
//import com.example.petinfo.dto.PetRegisterDTO;
//import com.example.petinfo.dto.PetUpdateDTO;
//import com.example.petinfo.service.PetInfoService;
//import com.example.user.context.UserContext;
import com.example.api.dto.PetInfoRespDTO;
import com.example.common.utils.UserContext;
import com.example.ranking.domain.dto.PetPopularRespDTO;
import com.example.ranking.service.RankingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 宠物信息控制器（对外提供API接口）
 */
@RestController
@RequestMapping("/api/v1/pets")
@Api(tags = "宠物信息管理接口")
@RequiredArgsConstructor
public class RankingController {

    private final RankingService rankingService;

    @GetMapping("/pet-popular")
    @ApiOperation("查询宠物人气榜（运输中/代养中品种数量排名，分页返回）")
    public IPage<PetPopularRespDTO> getPetPopularRanking(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        // 调用服务层获取分页人气榜（按数量降序）
        return rankingService.getPetPopularRanking(pageNum, pageSize);
    }

    @GetMapping("/pet-popular/refresh")
    @ApiOperation("手动刷新人气榜统计数据（可选，也可定时自动刷新）")
    public Boolean refreshPopularRanking() {
        // 手动触发统计数据更新（适用于测试或数据同步异常场景）
        return rankingService.refreshPopularRanking();
    }
}
